package com.shxy.api.common;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;

/**
 * 返回结果
 */
public class ApiResult extends HashMap<String, Object> {

    private ApiResult() {

    }

    public static ApiResult success() {
        return create(ResultCode.SUCCESS);
    }

    public static ApiResult fail() {
        return create(ResultCode.COMMON_FAIL);
    }

    public static ApiResult fail(ResultCode code, String msg) {
        code.setMessage(msg);
        return create(code);
    }

    public static ApiResult create(ResultCode code, Object data) {
        ApiResult rs = create(code);
        rs.put("data", data);
        return rs;
    }

    public static ApiResult create(ResultCode code) {
        ApiResult rs = new ApiResult();
        rs.put("code", code.getCode());
        rs.put("message", code.getMessage());
        return rs;
    }

    public static ApiResult create(Object data) {
        ApiResult rs = create(ResultCode.SUCCESS);
        rs.put("data", data);
        return rs;
    }
}
